/**
* 
* DPM for LEAT exercice with leat PROCESSOR  
* see <a href="{@docRoot}/Documentation/report.html"> for more information</a>
*  Copyright (c) 2009 Ecole Centrale de Nantes IRCCyN
* @author: Urunuela Richard
* @version 3.2
*/

package storm.DPMS;

import java.util.ArrayList;
import java.util.Iterator;

import storm.Timer;
import storm.Processors.LEATProcessor;
import storm.Processors.Processor;
import storm.Processors.LEATProcessor.States;
/**
 * 
 * @author richard
 *
 */
public class DPM_adap_LEAT extends DPM {
	
	int iteration = 0;
	private LEATProcessor CPU;
	/**
	 * au d??marrge tout les processeurs sont min freq;
	 */
	public void init(){
		ArrayList cpus = this.Kernel.getTasksListeManager().getALLProcessors();
		Iterator I = cpus.iterator();
		while (I.hasNext()){
			Processor P= (Processor) I.next();
		/*	if (P instanceof LEATProcessor){
				
				LEATProcessor LP = (LEATProcessor) P;
				LP.setFreq(5);
			}*/
		}
	}
	/**
	 * 
	 */
	public void setStandBy(){
		CPU.setState(States.STAND_BY);
	}
	public void setIdle(){
		CPU.setState(States.IDLE);
	}
	public void onTick(){
		ArrayList cpus = this.Kernel.getTasksListeManager().getALLProcessors();
		Iterator I = cpus.iterator();
		while (I.hasNext()){
			Processor P= (Processor) I.next();
			if (P instanceof LEATProcessor){
				LEATProcessor LP = (LEATProcessor) P;
			
				if ((this.Kernel.getTime() -(60*this.iteration))  == 6) {
					Timer timer1 = new Timer("setStandBy", 1 ,this);
					this.CPU = LP;
					Kernel.addTimer(timer1);
				}
				if ((this.Kernel.getTime() -(60*this.iteration))  == 8) {
					Timer timer2 = new Timer("setIdle", 1 ,this);
					Kernel.addTimer(timer2);
					this.CPU = LP;
				}
				if (this.Kernel.getTime() > 0 )
				if ( (this.Kernel.getTime() % 60 ) == 0) this.iteration ++;
			}
		}
	}
}
